package kr.co.boogui.actions.member;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.co.boogui.actions.ActionHandler;
import kr.co.boogui.dao.MemberDAO;
import kr.co.boogui.model.MemberVO;

public class LoginAction implements ActionHandler {
	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		String viewPage = "f|/WEB-INF/jsp/tiles/index.jsp";		
		MemberVO m = new MemberVO();
		m.setUid(req.getParameter("uid"));
		m.setPwd(req.getParameter("pwd"));
		MemberVO mv = MemberDAO.login(m);
		if (mv!=null) {
			System.out.println(mv.getMno());
			System.out.println(mv.getUname());
			HttpSession sess = req.getSession();
			sess.setAttribute("uid", m.getUid());
			sess.setAttribute("mno", mv.getMno());
			sess.setAttribute("uname", mv.getUname());
			viewPage = "r|index.bi";
		} else {
			req.setAttribute("action", "../member/loginfail.jsp");
		}
		
		return viewPage;
	}
}
